home *** CD-ROM | disk | FTP | other *** search
- class Car
- {
- var pos;
- var vel;
- var acc;
- var maxVel;
- var slideTime;
- var sEnemy;
- var energy;
- var blinkInd;
- var throwingTime;
- var autoTurnFactor;
- var bDestroyed;
- var bFromWeapon;
- var mcCanvas;
- var mcCar;
- var width;
- var height;
- var waitTime;
- var frame;
- var mcDamage;
- var lastFrame;
- var firstFrame;
- var turnDelay;
- var turnTime;
- var turnDir;
- function Car(sLinkageId, newPos, newVel, mcCanvasNew, depth, waitTimeNew)
- {
- this.pos = newPos.clone();
- this.vel = newVel.clone();
- this.acc = new flash.geom.Point(0,0);
- this.maxVel = 20;
- this.slideTime = 0;
- this.sEnemy = Game.getInstance().sEnemy;
- this.energy = 4;
- this.blinkInd = 0;
- this.throwingTime = 5;
- this.autoTurnFactor = 20;
- this.bDestroyed = false;
- this.bFromWeapon = false;
- this.mcCanvas = mcCanvasNew;
- this.mcCar = this.mcCanvas.attachMovie(sLinkageId,"mcCar" + depth,depth);
- this.width = this.mcCar._width;
- this.height = this.mcCar._height;
- this.waitTime = waitTimeNew;
- this.frame = 1;
- this.setFramesRange();
- this.setTurnDelay();
- this.draw();
- }
- function remove(Void)
- {
- this.mcCar.removeMovieClip();
- this.mcDamage.removeMovieClip();
- false;
- }
- function step(plPos, plVel, bmpShoulder)
- {
- if(this.waitTime > 0)
- {
- this.waitTime = this.waitTime - 1;
- return undefined;
- }
- this.frame = this.frame + 1;
- if(this.frame > this.lastFrame)
- {
- this.frame = this.firstFrame;
- }
- this.vel.x += this.acc.x;
- this.vel.y += this.acc.y;
- this.acc.x = 0;
- this.acc.y = 0;
- if(this.bDestroyed)
- {
- this.modifyVelocity(plVel);
- this.throwingTime = this.throwingTime - 1;
- }
- else
- {
- if(this.slideTime > 0)
- {
- this.slideTime = this.slideTime - 1;
- }
- else
- {
- this.vel.x *= 0.7;
- }
- if(Math.abs(this.vel.x) < 0.1)
- {
- this.vel.x = 0;
- }
- }
- this.pos.x += this.vel.x * this.vel.y / this.maxVel;
- this.pos.y += this.vel.y - plVel.y;
- if(!this.bDestroyed)
- {
- this.turnDelay = this.turnDelay - 1;
- if(this.turnDelay == 0)
- {
- this.setTurnDelay();
- }
- else if(this.turnDelay < this.turnTime)
- {
- this.acc.x = this.turnDir * this.vel.y / this.autoTurnFactor;
- }
- var _loc2_ = this.pos.y + 150;
- if(_loc2_ > Game.screenH)
- {
- _loc2_ = Game.screenH;
- }
- _loc2_ = Game.screenH - _loc2_;
- var _loc5_ = new flash.geom.Point(this.pos.x - this.width / 2 - 10,_loc2_);
- var _loc4_ = new flash.geom.Point(this.pos.x + this.width / 2 + 10,_loc2_);
- if(this.slideTime == 0)
- {
- if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,_loc5_))
- {
- this.acc.x = this.vel.y / 4;
- this.setTurnDelay();
- }
- else if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,_loc4_))
- {
- this.acc.x = (- this.vel.y) / 4;
- this.setTurnDelay();
- }
- }
- if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(this.pos.x,Game.screenH - this.pos.y)))
- {
- if(this.slideTime > 0)
- {
- this.blinkInd = 0;
- this.getDamage(4);
- }
- else
- {
- this.reactionOnShoulder(bmpShoulder);
- }
- }
- }
- if(this.pos.x < (- this.width) / 2 || this.pos.x > Game.screenW + this.width / 2)
- {
- this.onOutOfScreenH();
- }
- if(this.pos.y < -60 || this.pos.y > Game.screenH + 60)
- {
- this.onOutOfScreenV();
- }
- if(this.blinkInd > 0)
- {
- this.blinkInd = this.blinkInd - 1;
- this.blink();
- }
- }
- function draw(Void)
- {
- this.mcCar.gotoAndStop(this.frame);
- this.mcCar._x = this.pos.x;
- this.mcCar._y = Game.screenH - this.pos.y;
- if(this.bDestroyed)
- {
- this.mcCar._rotation += this.vel.y >= 2 ? this.vel.y * 3 : 6;
- this.mcDamage._x = this.mcCar._x;
- this.mcDamage._y = this.mcCar._y;
- }
- else
- {
- this.mcCar._rotation = this.vel.x * Math.ceil(this.vel.y / this.maxVel);
- }
- }
- function getRect(Void)
- {
- var _loc2_ = this.mcCar.getRect(this.mcCanvas);
- return new flash.geom.Rectangle(_loc2_.xMin,_loc2_.yMin,_loc2_.xMax - _loc2_.xMin,_loc2_.yMax - _loc2_.yMin);
- }
- function reactionOnShoulder(bmpShoulder)
- {
- if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(this.pos.x + 20,Game.screenH - this.pos.y)))
- {
- this.vel.x = (- this.vel.y) / 2;
- this.pos.x += this.vel.x;
- }
- else
- {
- this.vel.x = this.vel.y / 2;
- this.pos.x += this.vel.x;
- }
- }
- function getDamage(value)
- {
- if(this.blinkInd == 0)
- {
- this.blinkInd = 10;
- if(value == undefined)
- {
- this.energy -= 1;
- }
- else
- {
- this.energy -= value;
- }
- }
- if(this.energy <= 0 && !this.bDestroyed)
- {
- this.vel.y /= 2;
- this.bDestroyed = true;
- if(this.bFromWeapon)
- {
- var _loc2_ = Game.getInstance().sEnemy;
- Game.getInstance().addPoints(-200);
- Game.getInstance().showPoints(this.pos,-200);
- switch(_loc2_)
- {
- case "tesco":
- var _loc3_ = this.mcCar.getDepth() + 1;
- this.mcDamage = this.mcCanvas.attachMovie("car damage","mcDamage" + _loc3_,_loc3_);
- this.mcDamage.gotoAndStop(_loc2_);
- Sounds.playSound("skid");
- break;
- case "directLine":
- _loc3_ = this.mcCar.getDepth() + 1;
- this.mcDamage = this.mcCanvas.attachMovie("car damage","mcDamage" + _loc3_,_loc3_);
- this.mcDamage.gotoAndStop(_loc2_);
- this.mcCar._visible = false;
- Sounds.playSound("vapourise");
- break;
- case "sainsbury":
- _loc3_ = this.mcCar.getDepth() + 1;
- this.mcDamage = this.mcCanvas.attachMovie("car damage","mcDamage" + _loc3_,_loc3_);
- this.mcDamage.gotoAndStop(_loc2_);
- this.mcCar._visible = false;
- break;
- default:
- Sounds.playSound("skid");
- }
- }
- else
- {
- Game.getInstance().addPoints(-200);
- Game.getInstance().showPoints(this.pos,-200);
- Sounds.playSound("skid");
- }
- }
- else
- {
- this.setFramesRange();
- this.frame = this.firstFrame;
- }
- }
- function die(Void)
- {
- Game.getInstance().addRandomCar();
- Game.getInstance().removeRandomCar(this);
- }
- function setFramesRange(Void)
- {
- this.firstFrame = (4 - this.energy) * 25 + 1;
- if(this.firstFrame > 76)
- {
- this.firstFrame = 76;
- }
- this.lastFrame = this.firstFrame + 24;
- }
- function setTurnDelay(Void)
- {
- this.turnDelay = 60 + Math.round(30 * Math.random());
- this.turnTime = 10 + Math.round(20 * Math.random());
- this.turnDir = Math.random() >= 0.5 ? 1 : -1;
- this.autoTurnFactor = 20;
- }
- function checkDistance(refCar)
- {
- if(this.bDestroyed || this.waitTime > 0)
- {
- return undefined;
- }
- var _loc4_ = refCar.pos.x - this.pos.x;
- var _loc2_ = refCar.pos.y - this.pos.y;
- var _loc5_ = (this.width + refCar.width) / 2;
- var _loc6_ = (this.height + refCar.height) / 2;
- if(_loc2_ > 0 && _loc2_ < 150 && Math.abs(_loc4_) < _loc5_ && this.vel.y > refCar.vel.y)
- {
- this.acc.y = -1;
- }
- if(Math.abs(_loc2_) < _loc6_ && Math.abs(_loc4_) < _loc5_ + 10)
- {
- this.acc.x = 0;
- this.vel.x = 0;
- this.setTurnDelay();
- }
- }
- function checkCollision(refCar, bTakeDamage)
- {
- if(this.bDestroyed || this.waitTime > 0 || refCar.bExit)
- {
- return undefined;
- }
- var _loc5_ = refCar.pos.x - this.pos.x;
- var _loc7_ = refCar.pos.y - this.pos.y;
- var _loc9_ = (this.width + refCar.width) / 2;
- var _loc8_ = (this.height + refCar.height) / 2;
- if(Math.abs(_loc7_) < _loc8_ && Math.abs(_loc5_) < _loc9_)
- {
- var _loc3_ = this.vel.subtract(refCar.vel);
- var _loc11_ = !Application.bEasy ? 6 : 3;
- var _loc4_ = 10 * Math.floor(_loc3_.length / refCar.maxVel * _loc11_);
- if(_loc5_ > 0)
- {
- if(bTakeDamage)
- {
- this.vel.x = (- _loc3_.length) * 0.7;
- this.slideTime = 15;
- }
- else
- {
- this.vel.x = (- this.vel.y) / 4;
- }
- refCar.vel.x = refCar.vel.y / 4;
- }
- else
- {
- if(bTakeDamage)
- {
- this.vel.x = _loc3_.length * 0.7;
- this.slideTime = 15;
- }
- else
- {
- this.vel.x = this.vel.y / 4;
- }
- refCar.vel.x = (- refCar.vel.y) / 4;
- }
- var _loc10_ = this.vel.y;
- this.vel.y = refCar.vel.y * 0.95;
- refCar.vel.y = _loc10_ * 0.95;
- this.pos.x += this.vel.x;
- this.pos.y += this.vel.y;
- refCar.pos.x += refCar.vel.x;
- refCar.pos.y += refCar.vel.y;
- if(bTakeDamage && !refCar.bShield)
- {
- refCar.getDamage(_loc4_);
- if(Application.bEasy)
- {
- this.getDamage(1 + _loc4_ / 10);
- }
- else
- {
- this.getDamage(_loc4_ / 10);
- }
- Sounds.playSound("carCrash");
- }
- }
- }
- function checkWeapon(mcWeapon)
- {
- var _loc2_ = Game.getInstance().sEnemy;
- if(_loc2_ == "churchil" || _loc2_ == "asda" || _loc2_ == "lloyd" || _loc2_ == "elephant")
- {
- return undefined;
- }
- if((_loc2_ == "directLine" || _loc2_ == "aa") && mcWeapon.hitTest(this.mcCar._x,this.mcCar._y) || _loc2_ != "directLine" && _loc2_ != "aa" && mcWeapon.hitTest(this.mcCar))
- {
- this.energy = 0;
- this.bFromWeapon = true;
- this.getDamage();
- this.setFramesRange();
- this.frame = this.firstFrame;
- if(_loc2_ == "sainsbury")
- {
- Game.getInstance().removeShot();
- }
- }
- }
- function blink(Void)
- {
- var _loc4_ = undefined;
- var _loc2_ = Math.round(255 * this.blinkInd / 10);
- _loc4_ = new flash.geom.ColorTransform(1,1,1,1,_loc2_,_loc2_,_loc2_,0);
- var _loc3_ = new flash.geom.Transform(this.mcCar);
- _loc3_.colorTransform = _loc4_;
- }
- function modifyVelocity(plVel)
- {
- if(this.bFromWeapon)
- {
- var _loc3_ = Game.getInstance().sEnemy;
- switch(_loc3_)
- {
- case "tesco":
- this.vel.y = plVel.y - 5;
- break;
- case "directLine":
- this.vel.y = plVel.y - 5;
- break;
- case "sainsbury":
- this.vel.y = plVel.y - 5;
- break;
- case "moreThan":
- this.vel.y = plVel.y + 15;
- this.vel.x -= 1;
- break;
- default:
- this.vel.y = plVel.y - 8;
- }
- }
- else
- {
- this.vel.y = plVel.y - 2;
- this.vel.x = Math.abs(this.vel.x) / this.vel.x * 8;
- trace("vel: " + this.vel);
- }
- }
- function onOutOfScreenV(Void)
- {
- this.die();
- }
- function onOutOfScreenH(Void)
- {
- this.die();
- }
- }
-